package com.itheima.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.itheima.feign.GoodsFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping(value = "/consumer")
public class GoodsConsumerController {

    @Autowired
    private GoodsFeign goodsFeign;

    /**
     * feign调用
     */
    @GetMapping(value = "/one/{max}")
    public String getOne(@PathVariable(value = "max") Integer max) throws InterruptedException {
        TimeUnit.SECONDS.sleep(3);
        return goodsFeign.one(max);
    }


    @GetMapping(value = "/uone")
    @SentinelResource(value = "uone")
    public String uone(Integer max, String name) {
        return name + " | " + max;
    }


}
